﻿using UnityEngine;
using UnityEngine.UI;

namespace E.Story
{
    /// <summary>
    /// UI选项槽
    /// </summary>
    public class UIBranchItem : UIItem<ChoiceData>
    {
        /* 主要组件 */
        private StoryRunner storyRunner;
        private StoryUI storyUI;

        [Header("UI组件")]
        [SerializeField] private Button btnBranch;
        [SerializeField] private Text txtBranch;


        private void Start()
        {
            storyRunner = GetComponentInParent<StoryRunner>();
            storyUI = GetComponentInParent<StoryUI>();
        }

        public override void Refresh()
        {
            // 更新选项文本
            txtBranch.text = Data.Text;

            // 绑定点击事件
            btnBranch.onClick.RemoveAllListeners();
            btnBranch.onClick.AddListener(() =>
            {
                storyUI.HideBranchs();
                storyRunner.DoNode(Data.NextNodeID);
            });
        }
    }
}